package com.kang.controller;

import com.kang.entity.Essay;
import com.kang.entity.Notify;
import com.kang.mapper.EssayMapper;
import com.kang.mapper.NotifyMapper;
import com.kang.service.EssayService;
import com.kang.service.impl.EssayServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/return")
public class ReturnRedisDate {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private EssayMapper essayMapper;

    @Autowired
    private NotifyMapper notifyMapper;

    @GetMapping("redisDate")
    public void returnRedisDate() {
        List<Essay> list = essayMapper.selectList(null);
        for (Essay essay : list) {
            stringRedisTemplate.opsForValue().set("user:view:" + essay.getId(), String.valueOf(essay.getViewNum()));
            stringRedisTemplate.opsForValue().set("user:bookMark:" + essay.getId(), String.valueOf(essay.getFavorNum()));
            stringRedisTemplate.opsForValue().set("user:like:" + essay.getId(), String.valueOf(essay.getClickNum()));
            stringRedisTemplate.opsForValue().set("user:reply:" + essay.getId(), String.valueOf(essay.getReplayNum()));
        }
    }

    @GetMapping("redisDate02")
    public void redisDate02() {
        List<Notify> list = notifyMapper.selectList(null);
        for (Notify essay : list) {
            stringRedisTemplate.opsForValue().set("admin:view:" + essay.getId(), String.valueOf(essay.getViewNum()));
        }
    }
}
